package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.importRFCPanel.importPanelSubs.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.controller.importRFC.GenerateImportListThread;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.importRFCPanel.ImportRFCPanel;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.importRFCPanel.importPanelSubs.ImportRFCFunktionPanel;


public class AddFilesListener implements ActionListener {

	private ImportRFCPanel importRFCPanel;
	private DefaultListModel listModel;
	private GenerateImportListThread generateImportListThread;
	private ImportRFCFunktionPanel impP;
	
	public AddFilesListener(ImportRFCPanel importRFCPanel, ImportRFCFunktionPanel impP){
		this.importRFCPanel = importRFCPanel;
		this.impP=impP;
		
	}
	public void actionPerformed(ActionEvent e) {
		this.listModel = importRFCPanel.getListPanel().getListModel();
		JFileChooser fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		//fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fc.showOpenDialog(fc);
		File selFile =fc.getSelectedFile();
		String path = selFile.getAbsolutePath() + "/";
		importRFCPanel.setPath(path);
		System.out.println(importRFCPanel.getPath()+"***********");
		impP.setPath(importRFCPanel.getPath());
		File fpath = new File(path);
		generateImportListThread= new GenerateImportListThread(importRFCPanel, listModel, fpath);
		generateImportListThread.run();
		
//		impP.setPath(path);
		
	}

}
